﻿using System;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x02000074 RID: 116
	public class AimPoser : MonoBehaviour
	{
		// Token: 0x060004BA RID: 1210 RVA: 0x00031498 File Offset: 0x0002F698
		public AimPoser.Pose GetPose(Vector3 localDirection)
		{
			if (this.poses.Length == 0)
			{
				return null;
			}
			for (int i = 0; i < this.poses.Length - 1; i++)
			{
				if (this.poses[i].IsInDirection(localDirection))
				{
					return this.poses[i];
				}
			}
			return this.poses[this.poses.Length - 1];
		}

		// Token: 0x060004BB RID: 1211 RVA: 0x000314FC File Offset: 0x0002F6FC
		public void SetPoseActive(AimPoser.Pose pose)
		{
			for (int i = 0; i < this.poses.Length; i++)
			{
				this.poses[i].SetAngleBuffer((this.poses[i] != pose) ? 0f : this.angleBuffer);
			}
		}

		// Token: 0x04000334 RID: 820
		public float angleBuffer = 5f;

		// Token: 0x04000335 RID: 821
		public AimPoser.Pose[] poses = new AimPoser.Pose[0];

		// Token: 0x02000075 RID: 117
		[Serializable]
		public class Pose
		{
			// Token: 0x060004BD RID: 1213 RVA: 0x00031550 File Offset: 0x0002F750
			public bool IsInDirection(Vector3 d)
			{
				if (this.direction == Vector3.zero)
				{
					return false;
				}
				if (this.yaw <= 0f || this.pitch <= 0f)
				{
					return false;
				}
				if (this.yaw < 180f)
				{
					Vector3 forward = new Vector3(this.direction.x, 0f, this.direction.z);
					if (forward == Vector3.zero)
					{
						forward = Vector3.forward;
					}
					Vector3 from = new Vector3(d.x, 0f, d.z);
					float num = Vector3.Angle(from, forward);
					if (num > this.yaw + this.angleBuffer)
					{
						return false;
					}
				}
				if (this.pitch >= 180f)
				{
					return true;
				}
				float num2 = Vector3.Angle(Vector3.up, this.direction);
				float num3 = Vector3.Angle(Vector3.up, d);
				return Mathf.Abs(num3 - num2) < this.pitch + this.angleBuffer;
			}

			// Token: 0x060004BE RID: 1214 RVA: 0x000050A9 File Offset: 0x000032A9
			public void SetAngleBuffer(float value)
			{
				this.angleBuffer = value;
			}

			// Token: 0x04000336 RID: 822
			public bool visualize = true;

			// Token: 0x04000337 RID: 823
			public string name;

			// Token: 0x04000338 RID: 824
			public Vector3 direction;

			// Token: 0x04000339 RID: 825
			public float yaw = 75f;

			// Token: 0x0400033A RID: 826
			public float pitch = 45f;

			// Token: 0x0400033B RID: 827
			public float angleBuffer;
		}
	}
}
